//
//  CSSelectViewController.m
//  CSUIKit
//
//  Created by 浙大网新中研软件 on 2018/1/30.
//

#import "CSSelectViewController.h"

@interface CSSelectViewController ()

@property (nonatomic, strong) CS_Page_MultitpleSelectView *page_MultitpleSelectView;

@property (nonatomic, copy) MultitpleSelectedBlock saveHandler;

@end

@implementation CSSelectViewController

+(id)selectViewController:(NSString *)title selectItems:(NSArray *)selectItems savedHandler:(MultitpleSelectedBlock)savedHandler{
    
    CSSelectViewController *viewController = [CSSelectViewController new];
    viewController.page_MultitpleSelectView = [CS_Page_MultitpleSelectView page_MultitpleSelectView:title selectItems:selectItems savedHandler:nil];
    viewController.title = title;
    viewController.saveHandler = savedHandler;
    
    return viewController;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)viewDidLoad{
    
    [super viewDidLoad];
    
    [self.view addSubview:self.page_MultitpleSelectView];
    
    if (self.navigationController) {
        
        UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(saveClick)];
        self.navigationItem.rightBarButtonItems = @[barButtonItem];
        self.navigationItem.title = self.title;
        
    }
    
}

-(void)saveClick{
    
    [self.page_MultitpleSelectView refreshData];
    self.saveHandler(self.page_MultitpleSelectView.selectNames, self.page_MultitpleSelectView.selectCodes);
    [self.navigationController popViewControllerAnimated:YES];
    
}

@end
